package com.catsic.web.controllers;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.catsic.base.controller.BaseController;
import com.catsic.base.tree.TreeInfo;
import com.catsic.core.conditon.OrganCondition;
import com.catsic.core.tree.service.TreeService;

@Controller
@RequestMapping("/tree")
public class TreeController extends BaseController{
	
	@Autowired
	private TreeService treeService;
	
	/**
	 * organ:
	 * @author yangyd
	 * @param form
	 * @return
	 */
	@RequestMapping(value = "/organ")
	@ResponseBody
	public Map<String,Object> organ(String id){
		List<TreeInfo> form = treeService.organ(id);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put(CONTENT,form);
		map.put(RESULT,RESULT_SUCCESS);
		return map;
	}
	
	/**
	 * query:通过机构编码与名称查询机构
	 * @author yangyd
	 * @param form
	 * @return
	 */
	@RequestMapping(value = "/query" , method = RequestMethod.GET)
	@ResponseBody
	public Map<String,Object> query(OrganCondition condition){
		List<TreeInfo> form = treeService.organ(condition);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put(CONTENT,form);
		map.put(RESULT,RESULT_SUCCESS);
		return map;
	}
	
	/**
	 * menu:通过用户ID获取菜单数据
	 * @author yangyd
	 * @param form
	 * @return
	 */
	@RequestMapping(value = "/menu")
	@ResponseBody
	public Map<String,Object> menu(String id){
		List<TreeInfo> form = treeService.menu(id);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put(CONTENT,form);
		map.put(RESULT,RESULT_SUCCESS);
		return map;
	}
	
	/**
	 * resource:通过用户ID获取资源数据
	 * @author yangyd
	 * @param form
	 * @return
	 */
	@RequestMapping(value = "/resource")
	@ResponseBody
	public Map<String,Object> resource(String id){
		List<TreeInfo> form = treeService.resource(id);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put(CONTENT,form);
		map.put(RESULT,RESULT_SUCCESS);
		return map;
	}
	
	/**
	 * drawer:获取抽屉数据
	 * @author yangyd
	 * @param form
	 * @return
	 */
	@RequestMapping(value = "/drawer")
	@ResponseBody
	public Map<String,Object> drawer(){
		List<TreeInfo> form = treeService.drawer();
		Map<String,Object> map = new HashMap<String,Object>();
		map.put(CONTENT,form);
		map.put(RESULT,RESULT_SUCCESS);
		return map;
	}
	
	/**
	 * authArea:获取授权区域数据
	 * @author yangyd
	 * @param form
	 * @return
	 */
	@RequestMapping(value = "/authArea")
	@ResponseBody
	public Map<String,Object> authArea(String resourceCode){
		List<TreeInfo> form = treeService.authArea(resourceCode);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put(CONTENT,form);
		map.put(RESULT,RESULT_SUCCESS);
		return map;
	}
}
